﻿using Inaction.ServiceContract;
using System;

namespace Inaction.Message
{
    #region Messager
    public static class MessageHost
    {
        static IMessager messager;
        static IMessager Instance
        {
            get
            {
                if (messager == null)
                {
                    messager = ServiceContainer.GetService<IMessager>();
                    messager.OnReceiveMessage += (obj) =>
                    {
                        if (ReceivedMessage != null)
                            ReceivedMessage(obj);
                    };
                }
                return messager;
            }
        }
        public static event Action<MessageInfo> ReceivedMessage;
        public static void ShowMessage(string message)
        {
            if (ReceivedMessage != null)
            {
                ReceivedMessage(new StringMessage { Content = message });
            }
        }
        public static void SendMessage(MessageInfo message)
        {
            Instance.SendMessage(message);
        }
    }
    #endregion
}
